package WordFrequent;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Step {




        //将文件转化为字符串
        public static String ReadFile(File file){
                String words = "";
                try {
                        words = FileUtils.readFileToString(file);
                } catch (IOException e) {
                        e.printStackTrace();
                }
                words = words.toLowerCase();
                return  words;
        }




                        //将停词表转化为Stirng类型的List数组
        public static List<String> sort(String words) {
                String tmp = ""; //设置存储单词的字符串

                List<String> list = new ArrayList<String>();


                //将字符串和次数存入map中
                for (int i = 0; i < words.length(); i++) {
                        if ((words.charAt(i) < 123 && words.charAt(i) > 96) || words.charAt(i) == '\'') {
                                tmp += words.charAt(i);
                                if (i == words.length()-1){

                                        if (tmp != "") {
                                           list.add(tmp);

                                        }
                                }
                        } else if ( tmp != "" ) {
                                list.add(tmp);
                                tmp = "";

                        } else {
                                tmp = "";
                        }
                }


                return list;
        }

        public static void printf(List<Map.Entry<String, Integer>> list) {
                for (int i = 0 ;i <list.size(); i++){
                        System.out.printf("%s \t %d \t\n",list.get(i).getKey(),list.get(i).getValue());
                }
                System.out.println("==========================================================================");
        }


}
